import router from './router'
import store from './store'
import defaultSettings from '@/settings'
const whiteList = ['/login', '/auth-redirect']


router.beforeEach(async (to, from, next) => {
  // 无登陆模式开发
  if (!defaultSettings.needLogin) {
    console.log('to', to)
    store.dispatch('routers/getAlwaysRoutes')
    next()
    return
  }
  const { token } = store.getters.userInfo
  if (token) {
    if (to.path === '/login') {
      next({ path: '/' })
    } else {
      //
      store.dispatch('routers/getAlwaysRoutes')
      next()
    }
  } else {
    if (whiteList.indexOf(to.path) !== -1) {
      next()
    } else {
      next(`/login`)
    }
  }
})

